public class Solution {
    private int res;

    public int findKth(int[] a, int n, int K) {
        // write code here

        quickSort(a, 0, n-1, n, K);

        return res;

    }
    public void quickSort(int[] arr, int low, int high ,int n, int k) {
        /*这里和快排不一样没有等号*/
        if (low > high) {
            return  ;
        }



        int i = low, j = high;
        int pivot = arr[low];
        while (i < j) {
            // 注意一定要j在前面
            while (arr[j] >= pivot && i < j) {
                j--;
            }
            while (arr[i] <= pivot && i < j) {
                i++;
            }
            if (i < j) {
                int tmp = arr[i];
                arr[i] = arr[j];
                arr[j] = tmp;
            }
        }
        arr[low] = arr[i];
        arr[i] = pivot;
        if (i == n-k) {
            res = pivot;
            return;
        }
        quickSort(arr, low, j-1, n, k);
        quickSort(arr, j+1, high,n, k);
    }

}

